import data from "@/data/data";
import { getFoodTrucksList } from "@/app/actions";
export async function getAllFoodTrucks() {
  const data = await getFoodTrucksList({
    orderBy: {
      likeNum: "asc",
    },
    take: 50,
  });

  const results = [];

  for (const key in data) {
    results.push({
      id: key,
      ...data[key],
    });
  }

  return results;
}

export async function getCollectedFoodTrucks() {
  const allFoodTrucks = await getAllFoodTrucks();
  return allFoodTrucks.filter((data) => data.isCollected);
}

export async function getFoodTruckById(id) {
  const allFoodTrucks = await getAllFoodTrucks();
  return allFoodTrucks.find((data) => data.id === id);
}
